home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.3 Development Libraries / SGI IRIX 6.3 Development Libraries.iso / dist6.3 / gl_dev.idb / usr / share / src / OpenGL / teach / xlib / too-simple.c.z / too-simple.c
Encoding:
C/C++ Source or Header  |  1996-12-06  |  1.3 KB  |  53 lines

  1. #include <GL/glx.h>
  2. #include <unistd.h>
  3.  
  4. static int attributeList[] = { GLX_RGBA, None };
  5.  
  6. static Bool WaitForNotify(Display *d, XEvent *e, char *arg) {
  7.     return (e->type == MapNotify) && (e->xmap.window == (Window)arg);
  8. }
  9.  
  10. int main(int argc, char **argv) {
  11.     Display *dpy;
  12.     XVisualInfo *vi;
  13.     Colormap cmap;
  14.     XSetWindowAttributes swa;
  15.     Window win;
  16.     GLXContext cx;
  17.     XEvent event;
  18.  
  19.     /* get a connection */
  20.     dpy = XOpenDisplay(0);
  21.  
  22.     /* get an appropriate visual */
  23.     vi = glXChooseVisual(dpy, DefaultScreen(dpy), attributeList);
  24.  
  25.     /* create a GLX context */
  26.     cx = glXCreateContext(dpy, vi, 0, GL_TRUE);
  27.  
  28.     /* create a color map */
  29.     cmap = XCreateColormap(dpy, RootWindow(dpy, vi->screen),
  30.                                    vi->visual, AllocNone);
  31.  
  32.     /* create a window */
  33.     swa.colormap = cmap;
  34.     swa.border_pixel = 0;
  35.     swa.event_mask = StructureNotifyMask;
  36.     win = XCreateWindow(dpy, RootWindow(dpy, vi->screen), 0, 0, 100, 100,
  37.             0, vi->depth, InputOutput, vi->visual,
  38.             CWBorderPixel|CWColormap|CWEventMask, &swa);
  39.     XMapWindow(dpy, win);
  40.     XIfEvent(dpy, &event, WaitForNotify, (char*)win);
  41.  
  42.     /* connect the context to the window */
  43.     glXMakeCurrent(dpy, win, cx);
  44.  
  45.     /* clear the buffer */
  46.     glClearColor(1,1,0,1);
  47.     glClear(GL_COLOR_BUFFER_BIT);
  48.     glFlush();
  49.  
  50.     /* wait a while */
  51.     pause();
  52. }
  53.